﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class Admin_Timkiemlop : System.Web.UI.Page
{
    BUS_Class objC = new BUS_Class();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminLogin"] != null)
        {
            Page.Title = "Tìm Lớp Học";
            pnError.Visible = false;
            pnSuccess.Visible = false;
        }
        else Response.Redirect("dangnhap.aspx");
    }
    public string CheckTrangThai(object obj)
    {
        string b = obj.ToString();
        if (b == "1")
            return "Mở";
        else
            return "Đóng";
    }
    protected void btncapnhatl_Click(object sender, EventArgs e)
    {
        BUS_Class objC = new BUS_Class();
        string user = txttimml.Text.Trim();
        string name = txttimtl.Text.Trim();
        //string email = txttimemail.Text.Trim();
        //string add = txttimdiachi.Text.Trim();
        //lbthongbao.Text = "SELECT * FROM Customers WHERE Username Like '%"+user+"%' AND Name LIKE '"+name+"' AND Email LIKE '"+email+"' AND Address LIKE '%"+add+"%'";
        var dataC = objC.Class_getSearch(user, name);
        if (dataC.Rows.Count > 0)
        {
            ltrdiv.Text = "<div class='title'>Kết quả tìm kiếm</div>";
            lblSuccess.Text = "Có " + dataC.Rows.Count + " kết quả được tìm thấy.";
            pnError.Visible = false;
            pnSuccess.Visible = true;
            //lbthongbao.ForeColor = Color.Blue;
            gvlop.DataSource = dataC;
            gvlop.DataBind();
        }
        else
        {
            lblError.Text = "Không Tìm thấy Kết quả nào.";
            pnError.Visible = true;
            pnSuccess.Visible = false;
            //lbthongbao.ForeColor = Color.Red;
            gvlop.DataSource = dataC;
            gvlop.DataBind();
        }

    }
    public void LoadData()
    {
        gvlop.DataSource = objC.Class_getAllData();
        gvlop.DataBind();
    }
    protected void btnxoal_Click(object sender, EventArgs e)
    {
        try
        {
            int count = 0;
            for (int i = 0; i < gvlop.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)gvlop.Rows[i].Cells[0].FindControl("chklop");
                if (chk.Checked)
                {
                    count++;
                    int id = int.Parse(gvlop.Rows[i].Cells[1].Text);
                    //lap danh sach xoa
                    objC.Class_addtodel(id);
                }
            }
            //tien hanh xoa
            if (count > 0)
            {
                if (objC.Class_del())
                {
                    LoadData();
                }
                else
                {
                    Response.Write("<script>alert(\"Xóa không thành công\")</script>");
                }
            }
            else Response.Write("<script>alert(\"Bạn chưa chọn mục xóa\")</script>");

        }
        catch (Exception ex)
        {

            throw new Exception(ex.Message);
        }
    }
}